const express=require('express');
const index=express.Router();
const userComment = express.Router()
const axios = require('axios')
const { render } = require('art-template')
const multipart = require('connect-multiparty');
const FormData = require('form-data')
var multipartMiddleware = multipart()
const fs = require("fs");
index.get('/',(req, res)=>{
    res.render('admin/index',{userInfo:"超级管理员"});
});
index.get('/text',(req, res)=>{
    res.render('admin/text',{userInfo:"超级管理员"});
});
index.post('/textFile',multipartMiddleware,(req, res)=>{
    console.log("-------------------------------------");
    console.log(req.files);
    // res.send("文件上传")
    let formData = new FormData()
    for(var a in req.files){  
                  //接收前台传来的图片路径
        formData.append('files', fs.createReadStream(req.files[a].path))
    }
    axios.post(`http://www.mianded.top:8081/comment/commentGoods`,
        formData, { headers: formData.getHeaders() 
    }).then((data) => {
        // console.log(data)
        console.log(333333333);
        console.log("success============")
        res.send({ data: data.data })

    }).catch((err) => {
        res.send(err)
    })
});
module.exports=index;



